package com.mp.approvalreq.servlet;

import com.alibaba.fastjson.JSONObject;
import com.mp.approvalreq.service.ApprovalOperateServicePrx;
import com.mp.approvalreq.util.ServiceUtils;
import com.mp.user.entity.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 归档全部,[抄送我的]一栏侧滑
 *
 * @author Administrator
 */
@WebServlet("/fileAll")
public class FileAll extends AbstractServlet {

	private static final long serialVersionUID = -6524473373623928868L;

	private static final Logger logger = LoggerFactory.getLogger(FileAll.class);

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		try {
			User user = getReqUser(req);
			logger.info("操作用户:{}", user.getContactId());

			ApprovalOperateServicePrx approvalOperateServicePrx = ServiceUtils.getApprovalOperateServicePrx();
			approvalOperateServicePrx.fileAllRequest(user);

			returnResult(resp);
		} catch (Throwable e) {
			onThrowable(req, resp, e);
		}
	}

	private void returnResult(HttpServletResponse resp) throws IOException {
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("result", "0");
		jsonObject.put("res_info", "提交成功");

		logger.info(jsonObject.toJSONString());

		printJson(resp, jsonObject.toJSONString());
	}

}
